import {
  HTTP
} from '../utils/http.js'

class AboutModel extends HTTP {
  constructor() {
    super()
  }

  login(success) {
    var This = this;
    wx.login({
      success : res => {
        let code = res.code;
        wx.getSetting({
          success : res => {
            if(res.authSetting['scope.userInfo']){   //判断用户是否已经授权
              wx.getUserInfo({
                success : res =>{
                  let data = {
                    raw_data:res.rawData,
                    signature:res.signature,
                    code:code
                  }
                  var params = {
                    url: 'wxAppLogin',
                    success: success,
                    method: 'POST',
                    data:data
                  }
                  this.request(params)
                }
              })  //getUserInfo结尾
            }
          }
        }) //getSetting结尾
      }
    }) //login结尾
  }

  getUserInfo(success){
    var userToken = wx.getStorageSync('userToken');
    let data = {
      user_token:userToken,
    }
    var params = {
      url: 'getUserInfo',
      success: success,
      method: 'POST',
      data:data
    }
    this.request(params)
  }
}

export {
  AboutModel
}